function updateAllSex(type)
{
    $('.shirtForm').each(function(i, obj) {
        id = $(this).find(".shirtID").val();
        if (type == "H")
            $(this).find(".sexH").prop('checked', true);
        else
            $(this).find(".sexF").prop('checked', true);

        updateShirt(id);
    });

}


function updateAllColor(color)
{
    $('.shirtForm').each(function(i, obj) {
        id = $(this).find(".shirtID").val();
        if (color != "random")
            changeShirtColor(id, color);
        else
            selectRandomColor(id);
    });

}

function updateAllSize(size)
{
	$('.shirtForm').each(function(i, obj) {
        id = $(this).find(".shirtID").val();
        $(this).find(".shirtSize").val(size);
        updateShirt(id);
    });
}

function quickSearch()
{
    $('#searchProgress').fadeTo(0,1);
	jQuery.ajax({
		type: 'GET',
		url: 'pages/controller/ajax/search.php',
		data: {
			search: $('#search').val(),
			price: $('input[type=radio][name=price]:checked').val(),
			brands: getBrand()
		},
		
		success: function(data, textStatus, jqXHR) {
			 $('#searchResult').html(data);
			 $('#searchProgress').fadeTo(0,0);
			 updateAllSex($('input[type=radio][name=sexSearch]:checked').val());
			 updateAllColor($('input[type=radio][name=color]:checked').val());
			 updateAllSize($('input[type=radio][name=size]:checked').val());
		},
		
		error: function(jqXHR, textStatus, errorThrown) {
			displayMsg("Impossible d'ajouter les articles au panier: Une erreur est survenue.",5000,true);
			$('#searchProgress').fadeTo(0,0);
		}
	});
}

function getBrand()
{
	res = new Array();
	$i=0;
	if($('#brand_Rockstar:checked').val())
	{
		res[$i++] = "Rockstar";
	}
	if($('#brand_Aubergine:checked').val())
	{
		res[$i++] = "Aubergine";
	}
	if($('#brand_BioFood:checked').val())
	{
		res[$i++] = "BioFood";
	}
	if($('#brand_HappyLove:checked').val())
	{
		res[$i++] = "HappyLove";
	}
	if($('#brand_Hipster9000:checked').val())
	{
		res[$i++] = "Hipster9000";
	}
	if($('#brand_PeaceAndLove:checked').val())
	{
		res[$i++] = "PeaceAndLove";
	}
	return res;
}
